//
//  CTCNavigationController.m
//  ConsultantVersion
//
//  Created by 李小龙 on 2017/3/25.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "CTCNavigationController.h"

@interface CTCNavigationController ()
@end

@implementation CTCNavigationController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


// 设置导航条的样式
+(void)initialize
{
    UINavigationBar *bar = [UINavigationBar appearance];
    [bar setBackgroundImage:[UIImage imageWithColor:HEXCOLOR(0x2e8ce5)]
              forBarMetrics:UIBarMetricsDefault];
    [bar setTitleTextAttributes:@{NSFontAttributeName:SYSTEMFONT(17),NSForegroundColorAttributeName:[UIColor whiteColor]}];
    bar.tintColor = [UIColor whiteColor];
    
    
    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
    
    // 设置普通状态
    NSDictionary *dicNormal = @{
                                NSForegroundColorAttributeName:[UIColor whiteColor],
                                NSFontAttributeName:SYSTEMFONT(14)
                                };
    
    [barItem setTitleTextAttributes:dicNormal  forState:UIControlStateNormal];
    // 设置不可用状态
    NSDictionary *dicDisabled = @{
                                  NSForegroundColorAttributeName:[UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.7],
                                  NSFontAttributeName:[UIFont systemFontOfSize:14]
                                  };
    [barItem setTitleTextAttributes:dicDisabled  forState:UIControlStateDisabled];
    
    
    
}

/**
 重写这个方法的目的是拦截所有push进来的控制器
 
 @param viewController 即将push进来的控制器
 @param animated 是否有动画效果
 */
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.viewControllers.count > 0) {
        // 这是push进来的控制器器不是第一个控制器
        viewController.hidesBottomBarWhenPushed = YES; // 自动隐藏tabbar
        // 设置返回状态的按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(backBtnClick) image:@"icon-denglu-fanhui副本" highImage:@"icon-denglu-fanhui副本"];
    }
    [super pushViewController:viewController animated:animated];
}

-(void)backBtnClick
{
    [self popViewControllerAnimated:YES];
    
}
@end
